home *** CD-ROM | disk | FTP | other *** search
/ The Very Best of Atari Inside / The Very Best of Atari Inside 1.iso / mint / mntlb20 / lib / uname.c < prev    next >
C/C++ Source or Header  |  1992-02-07  |  2KB  |  84 lines

  1. /*
  2.  * uname() emulation by Dave Gymer. In the public domain.
  3.  * Bugs:
  4.  *    The MiNT version stuff is in the release field. According to the GNU
  5.  *    shell utils this is the way SunOS does it, so we put the TOS
  6.  *    version number in the 'version' field (even under MiNT).
  7.  *
  8.  * (Modified slightly by ERS.)
  9.  */
  10.  
  11. #include <stdlib.h>
  12. #include <unistd.h>
  13. #include <sys/utsname.h>
  14. #include <osbind.h>
  15. #include <stdio.h>
  16. #include <string.h>
  17.  
  18. extern int __mint;
  19. __EXTERN int gethostname __PROTO((char *buf, size_t len));
  20.  
  21. static long _mch;    /* value of the _MCH cookie, if any */
  22. static int tosvers;    /* TOS version number */
  23.  
  24. /*
  25.  * get operating system information; must execute in supervisor mode
  26.  */
  27.  
  28. static void
  29. getinfo()
  30. {
  31.     long *cookie, *sysbase;
  32.  
  33. /* get _MCH cookie value */
  34.     cookie = *((long **) 0x5a0);
  35.     if (cookie) {
  36.         while (*cookie) {
  37.             if (*cookie == 0x5f4d4348L) {    /* _MCH */
  38.                 _mch = cookie[1];
  39.                 break;
  40.             }
  41.             cookie += 2;
  42.         }
  43.     }
  44.  
  45. /* get TOS version number */
  46.     sysbase = *((long **)(0x4f2));
  47.     tosvers = sysbase[0] & 0x0000ffff;
  48. }
  49.  
  50. #define HILO(x) (int) ((x >> 8) & 255), (int) (x & 255)
  51.  
  52. int
  53. uname(buf)
  54.     struct utsname *buf;
  55. {
  56.     if (!tosvers)
  57.         (void)Supexec(getinfo);
  58.  
  59.     strcpy(buf->sysname, __mint ? "MiNT" : "TOS");
  60.  
  61.     if (gethostname(buf->nodename, (size_t) 15))
  62.         strcpy(buf->nodename, "??node??");
  63.  
  64.     if (__mint)
  65.         sprintf(buf->release, "%d.%d", HILO(__mint));
  66.     else
  67.         buf->release[0] = 0;
  68.  
  69.     sprintf(buf->version, "%d.%d", HILO(tosvers));
  70.  
  71.     switch((_mch >> 16) & 0x0ffffL) {
  72.     case 0:
  73.         strcpy(buf->machine, "atarist"); break;
  74.     case 1:
  75.         strcpy(buf->machine, "atariste"); break;
  76.     case 2:
  77.         strcpy(buf->machine, "ataritt"); break;
  78.     default:
  79.         strcpy(buf->machine, "atari");
  80.     }
  81.  
  82.     return 0;
  83. }
  84.